<template>
<div>
  <div class="breadcrumb-container">
    <el-breadcrumb separator="Ξ">
      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item v-for="(item, index) in breadcrumbItem" :key="index">{{item.name}}</el-breadcrumb-item>
    </el-breadcrumb>
  </div>

  <div class="search-container">
    <el-form :inline="true" :model="formSearch" class="search-form">
      <el-form-item>
        <el-input v-model="title" placeholder="标题"></el-input>
      </el-form-item>
      <el-button type="primary" @click="getNewsList(1)">
        <i class="el-icon-search"></i>查询
      </el-button>
    </el-form>
  </div>

  <div class="news-container">
    <div class="news-list">
      <div class="news-item" v-for="item in newsList" :key="item.id" @click="toNewsDetail(item)">
        <el-image class="news-image" :src="baseUrl + item.picture" fit="cover"></el-image>
        <div class="news-content">
          <div class="news-title">{{item.title}}</div>
          <div class="news-intro">{{item.introduction}}</div>
        </div>
      </div>
    </div>

    <el-pagination
      background
      class="pagination"
      :pager-count="7"
      :page-size="pageSize"
      :page-sizes="pageSizes"
      prev-text="<"
      next-text=">"
      :hide-on-single-page="true"
      :layout='["total","prev","pager","next","sizes","jumper"].join()'
      :total="total"
      @current-change="curChange"
      @prev-click="prevClick"
      @next-click="nextClick"
    ></el-pagination>
  </div>
</div>
</template>

<script>
  export default {
    //数据集合
    data() {
      return {
        baseUrl: this.$config.baseUrl,
        breadcrumbItem: [
          {
            name: '活动公告'
          }
        ],
        newsList: [],
        total: 1,
        pageSize: 10,pageSizes: [10,20,30,50],
        totalPage: 1,
		layouts: '',
        title: '',
      }
    },
    created() {
		this.getNewsList(1);
    },
    //方法集合
    methods: {
      getNewsList(page) {
        let params = {page, limit: this.pageSize,sort:'addtime',order:'desc'};
        let searchWhere = {};
        if(this.title != '') searchWhere.title = '%' + this.title + '%';
        this.$http.get('news/list', {params: Object.assign(params, searchWhere)}).then(res => {
          if (res.data.code == 0) {
            this.newsList = res.data.data.list;
            this.total = res.data.data.total;
            this.pageSize = res.data.data.pageSize;this.pageSizes = [this.pageSize, this.pageSize*2, this.pageSize*3, this.pageSize*5];
            this.totalPage = res.data.data.totalPage;
          }
        });
      },
      curChange(page) {
        this.getNewsList(page);
      },
      prevClick(page) {
        this.getNewsList(page);
      },
      nextClick(page) {
        this.getNewsList(page);
      },
      toNewsDetail(item) {
        this.$router.push({path: '/index/newsDetail', query: {detailObj: JSON.stringify(item)}});
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.breadcrumb-container {
  padding: 12px;
  background: linear-gradient(180deg, #eee 0%, #fff 32%, #eee 100%);
  box-shadow: 0 0 6px #ccc;
  border: 1px solid #fff;
  border-width: 1px 0;

  .el-breadcrumb {
    width: 1200px;
    margin: 0 auto;
    font-size: 14px;
    line-height: 1;
  }
}

.search-container {
  margin: 20px auto;
  width: 1200px;

  .search-form {
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .el-button {
    margin-left: 10px;
  }
}

.news-container {
  width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);

  .news-list {
    .news-item {
      display: flex;
      padding: 20px 0;
      border-bottom: 1px dashed #ddd;
      cursor: pointer;
      transition: all 0.3s;

      &:hover {
        transform: translateY(-3px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
      }

      .news-image {
        width: 200px;
        height: 140px;
        border-radius: 4px;
        object-fit: cover;
      }

      .news-content {
        flex: 1;
        margin-left: 20px;
        
        .news-title {
          font-size: 18px;
          font-weight: bold;
          color: #333;
          margin-bottom: 10px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .news-intro {
          font-size: 14px;
          color: #666;
          line-height: 1.6;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 3;
          overflow: hidden;
        }
      }
    }
  }

  .pagination {
    margin-top: 30px;
    text-align: center;
  }
}

.el-pagination {
  /deep/ .el-pagination__total {
    color: #666;
  }

  /deep/ .btn-prev,
  /deep/ .btn-next {
    background: #f5f7fa;
    color: #606266;
    border-radius: 4px;
    
    &:disabled {
      color: #c0c4cc;
    }
  }

  /deep/ .el-pager .number {
    background: #f5f7fa;
    color: #606266;
    border-radius: 4px;
    
    &:hover,
    &.active {
      background: #409eff;
      color: #fff;
    }
  }
}
</style>
